home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 002 / xrf / xrf3.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  3KB  |  104 lines

  1. /*
  2.  *                      ***************
  3.  *                      * X R F 3 . C *
  4.  *                      ***************
  5.  *
  6.  * Sorted cross reference listing routines. 'prtree' performs an
  7.  * inorder traversal of the id tree, printing the references to'
  8.  * each id while visiting that node.
  9.  *
  10.  * Version V1.3          9-May-80
  11.  * Version V1.4        10-Jul-80 MM    Bummed code, added 80 col. support
  12.  */
  13.  
  14. #include <stdio.h>
  15. #include "xrf.h"
  16.  
  17.  
  18. /*
  19.  * Inorder tree traversal.
  20.  */
  21.  
  22. prtree(link)
  23. struct idt *link;
  24.  
  25.    {
  26.    if (debug) {printf("xrf: beginning prtree\n");}
  27.    if (link != NULL)
  28.       {
  29.       prtree(link->left);       /* Visit the left */
  30.       prtrefs(link);            /* Print refs for this one */
  31.       prtree(link->right);      /* Visit the right */
  32.       }
  33.    }
  34.  
  35. /*
  36.  * List out a line of references.
  37.  * Start new page if it gets full.
  38.  */
  39.  
  40. lstrefs()
  41.    {
  42.    if(++linpg > MAXLIN)                 /* New page if necessary */
  43.       newpage();
  44.    fputs(scanbf, lst);                 /* Write out the string */
  45.    fputc('\n',lst);            /* Terminate with newline */
  46.    }
  47.  
  48. /*
  49.  * Print id and references.
  50.  * Share scan buffer for printout.
  51.  * Use newpag.
  52.  *
  53.  * The ref line number field width is hard-wired into the format statement.
  54.  * Trouble is, #define's don't (and shouldn't!) substitute into strings,
  55.  * like formats.
  56.  *
  57.  * Current values are 5 char field (RSIZE) and rperline ref's per line.
  58.  */
  59.  
  60. prtrefs(link)
  61. struct idt *link;
  62.  
  63.    {
  64.    register struct ref *r;              /* Ref chain pointer */
  65.    register char *p;                    /* Fast scan buffer pointer */
  66.    register int j;                      /* Counts refs printed on a line */
  67.  
  68.    char *cpystr();                      /* cpystr returns char pointer */
  69.  
  70.    if (debug) {printf("xrf: beginning prtrefs\n");}
  71.    r = link->first;                     /* r --> head of ref chain */
  72.    p = scanbf;                          /* p --> start of scan buffer */
  73.    j = 0;                               /*Init refs-per-line */
  74.  
  75.    p = cpystr(p, link->keyp);           /* Start with the id string */
  76.    while(p < &scanbf[NCPS]) {             /* Pad with blanks */
  77.          *p++ = ' ';
  78.    }
  79.    *p++ = '\t';                         /* Followed by a tab */
  80.    do
  81.       {                                 /* List Reference line numbers */
  82.       if(j >= rperline)                 /* If this line is full */
  83.          {
  84.          *p = '\0';                     /* Terminate with null */
  85.          lstrefs();                     /* Write it out */
  86.          p = scanbf;                    /* Reset buffer pointer */
  87.          j = 0;                         /* Reset refs-on-line count */
  88.          *p++ = '\t';                   /* Start cont. line w/ 2 tabs */
  89.      *p++ = '\t';
  90.          }
  91.       j++;
  92.       sprintf(p,"%5d", r->lno);         /* Insert reference into buffer */
  93.       p += RSIZE;                       /* Update buffer pointer */
  94.       r = r->next;                      /* On down the chain */
  95.       }
  96.    while(r != NULL);                    /* Until the end */
  97.    *p = '\0';                           /* Terminate with null */
  98.     if (debug) {printf("xrf: all references done; p %d\n",p);}
  99.     if (debug) {printf("xrf: scanbf: \"%s\"\n",scanbf);}
  100.    lstrefs();                           /* Write the line out */
  101.    }
  102.  
  103.  
  104.